<?php

namespace App\Models;
use stdClass;

class RoleModel extends BaseModel {

	public function __construct() {
		parent::__construct();
		$this -> _table = "user";
	}

	public function getCountRole($roleid) {
		$sql = "select  ID,UserName,NickName  from `user` where RoleID = '" . $roleid . "'";
		$sth = $this -> _dbHandle -> prepare($sql);
		$sth -> execute();
		return $sth -> fetchAll();
	}

	public function SelectUserList($test) {
		$sth = $this -> _dbHandle -> prepare($test);
		$sth -> execute();
		return $sth -> fetchAll();
	}

	public function getCountw($sumw) {
		$sth = $this -> _dbHandle -> prepare($sumw);
		$sth -> execute();
		return $sth -> fetchAll();
	}

	public function roleupdata($username, $roleid) {
		$table = $this -> _table;
		$sql1 = "select * from $table where UserName ='" . $username . "'";
		$sql2 = "update $table set RoleId = '" . $roleid . "' where UserName ='" . $username . "'";
		if ($this -> query($sql1)) {
			if ($this -> query($sql2)) {
				$msg = array('message' => '修改成功', 'code' => 0);
			} else {
				$msg = array('message' => '修改失败（原因：未修改信息）', 'code' => 1);
			}
		} else {
			$msg = array('message' => '修改失败（原因：未修改信息）', 'code' => 2);
		}
		return json_encode($msg);
	}

}
